package com.huilan.hgt.service.impl;

import com.huilan.hgt.entity.Role;
import com.huilan.hgt.entity.UserRole;
import com.huilan.hgt.mapper.UserRoleMapper;
import com.huilan.hgt.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @author ghy
 * @since 2018-11-02
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Autowired
    UserRoleMapper userRoleMapper;

    /**
     * 根据用户ID查询角色
     *
     * @param userId
     * @return
     */
    @Override
    public Integer getRoleByUserId(Integer userId) {

        Map<String,Object> params = new HashMap<>();
        params.put(UserRole.USER_ID,userId);
        List<UserRole> userRoleList = userRoleMapper.selectByMap(params);
        if(userRoleList.size()>0){
            return userRoleList.get(0).getRoleId();
        }
        return null;
    }

    /**
     * 根据用户ID查询该用户角色
     *
     * @param userId
     * @return
     */
    @Override
    public List<Role> getRoleListByUserId(Integer userId) {
        return userRoleMapper.getRoleListByUserId(userId);
    }
}
